// Kony

#pragma once

#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "BaseUserWidget.generated.h"


UENUM(BlueprintType)
enum class EWidgetType : uint8
{
	SubWidget   UMETA(DisplayName="子界面"),
	MainWidget  UMETA(DisplayName="主界面"),
	// 以后可以继续扩展
	FloatingPanel UMETA(DisplayName="浮动面板"),
	Tooltip      UMETA(DisplayName="提示面板")
};
// 新增：可拖动菜单类型，用于区分拖动目标
UENUM(BlueprintType)
enum class EDraggableMenuType : uint8
{
	None            UMETA(DisplayName="无"),
	SpellMenu       UMETA(DisplayName="法术菜单"),
	AttributeMenu   UMETA(DisplayName="属性菜单"),
};
/**
 * 用户控件的基类
 */
UCLASS()
class GASC_HUANLING_API UBaseUserWidget : public UUserWidget
{
	GENERATED_BODY()
public:
	UFUNCTION(BlueprintCallable)
	void SetWidgetController(UObject* InWidgetController);
	UPROPERTY(BlueprintReadOnly)
	TObjectPtr<UObject> WidgetController;//用户空间控制器
	
	//用户小组件类型
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="UI Interaction")
	EWidgetType WidgetType = EWidgetType::SubWidget; // 默认子界面
	//是否点击到这个UI时，禁止移动
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "UI Interaction")
	bool bIsStopMove = true;
	// 是否允许拖拽
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "UI Interaction")
	bool bIsDraggable = false;
	// 新增：当前小部件对应的菜单类型（在蓝图中为子界面设置）
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "UI Interaction")
	EDraggableMenuType ThisWidgetMenuType = EDraggableMenuType::None;
	//鼠标监听事件
	virtual void NativeConstruct() override;
	virtual FReply NativeOnMouseWheel(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent) override;
	virtual FReply NativeOnMouseMove(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent) override;
	virtual FReply NativeOnMouseButtonUp(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent) override;
	//消费掉这些点击事件 就可以做到 点击UI的时候不移动，点击非UI才移动
	virtual FReply NativeOnMouseButtonDoubleClick( const FGeometry& InGeometry, const FPointerEvent& InMouseEvent ) override;
	virtual FReply NativeOnMouseButtonDown(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent) override;
	
	UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (BindWidgetOptional))
	class UCanvasPanel* CanvasPanel_Root;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (BindWidgetOptional))
	class UOverlay* Overlay_SpellMenu;
	// 新增：可选的属性菜单 Overlay
	UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (BindWidgetOptional))
	class UOverlay* Overlay_AttributeMenu;

protected:
	bool bDragging = false;
	float CurrentZoom = 1.0f;
	FVector2D LastMouseScreenPos;
	// 记录：最近一次点击的菜单类型（SubWidget 在 MouseDown 时赋值，MainWidget 在 Move 时读取）
	static EDraggableMenuType ClickedMenuType;
	// 根据菜单类型获取对应 Overlay（MainWidget 拖拽用）
	class UOverlay* GetOverlayByMenuType(EDraggableMenuType MenuType) const;
	
	UFUNCTION(BlueprintImplementableEvent)
	void WidgetControllerSet();

	
	virtual void NativeOnMouseLeave(const FPointerEvent& InMouseEvent) override;
	
};
